﻿using System;
using System.Globalization;
using System.Windows.Forms;
using ResxCrunch.Business;
using ResxCrunch.Properties;
using ResxCrunch.Utils.FileData;
using System.IO;
using ResxCrunch.Business.Managers;
using ResxCrunch.Utils;

namespace ResxCrunch
{
    /// <summary>
    /// Load form class
    /// </summary>
    public partial class FrmLoad : Form
    {
        #region Attributes
        private Enums.LoadModes mode = Enums.LoadModes.Data;
        #endregion Attributes

        #region Initialization
        /// <summary>
        /// Initializes a new instance of the <see cref="FrmLoad"/> class.
        /// </summary>
        public FrmLoad()
        {
            this.InitializeComponent();
        }

        /// <summary>
        /// Handles the Load event of the FrmLoad control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
        private void FrmLoad_Load(object sender, EventArgs e)
        {
            this.InitializeMode();
            this.LoadForm();

            this.Enablings();
        }

        /// <summary>
        /// Initializes the help area of the form
        /// </summary>
        private void InitializeMode()
        {
            switch (this.Mode)
            {
                case Enums.LoadModes.Additional:
                    pictureBoxMode.Image = Resources.LoadAdditional;
                    labelInfo.Text = "Select the datasource from which the additional data will be loaded. The loaded additional data will be added to the end of the already loaded data. The structure of the additional data must exactly match the original data.";
                    this.Text = "Load additional data";
                    break;
                case Enums.LoadModes.Patch:
                    pictureBoxMode.Image = Resources.LoadPatch;
                    labelInfo.Text = "Select the datasource for the patch data. Data from the patch will be used to overwrite the existing data. If the patch contains additional columns these will be added to the original data. If the patch contains additional rows these will NOT be added to the original data.";
                    this.Text = "Load patch";
                    break;
                default:
                    pictureBoxMode.Image = Resources.Load;
                    labelInfo.Text = "Select the source where the data will be loaded from. In some cases the data must have a specific format.";
                    break;
            }
        }
        #endregion Initialization

        #region Properties
        /// <summary>
        /// Load mode od the form
        /// </summary>
        public Enums.LoadModes Mode
        {
            get { return mode; }
            set { mode = value; }
        }

        /// <summary>
        /// Gets or sets the selected format.
        /// </summary>
        /// <value>The selected format.</value>
        public Utils.Enums.Format SelectedFormat { get; set; }

        /// <summary>
        /// Gets the resx group data.
        /// </summary>
        /// <value>The resx group data.</value>
        public ResxGroupData ResxGroupInfo
        {
            get
            {
                return new ResxGroupData(txtResxGroupDir.Text, chkResxGroupRecursive.Checked);
            }
        }

        /// <summary>
        /// Gets the RESX file data.
        /// </summary>
        /// <value>The RESX file data.</value>
        public ResxData ResxFileInfo
        {
            get
            {
                return new ResxData(txtResxPath.Text);
            }
        }

        /// <summary>
        /// Gets the resx group data.
        /// </summary>
        /// <value>The resx group data.</value>
        public ResourceGroupData ResourceGroupInfo
        {
            get
            {
                return new ResourceGroupData(txtResourceGroupDir.Text, chkResourceGroupRecursive.Checked);
            }
        }

        /// <summary>
        /// Gets the Resource file data.
        /// </summary>
        /// <value>The Resource file data.</value>
        public ResourceData ResourceFileInfo
        {
            get
            {
                return new ResourceData(txtResourcePath.Text);
            }
        }

        /// <summary>
        /// Gets the CSV file data.
        /// </summary>
        /// <value>The CSV file data.</value>
        public CsvData CsvFileInfo
        {
            get
            {
                return new CsvData(txtCsvPath.Text, true, 0);
            }
        }

        /// <summary>
        /// Gets the Xml file data.
        /// </summary>
        /// <value>The Xml file data.</value>
        public XmlData XmlFileInfo
        {
            get
            {
                return new XmlData(txtXmlPath.Text);
            }
        }

        /// <summary>
        /// Gets the android group info.
        /// </summary>
        /// <value>The android group info.</value>
        public AndroidGroupData AndroidGroupInfo
        {
            get
            {
                return new AndroidGroupData(txtAndroidGroupPath.Text, chkAndroidGroupRecursive.Checked);
            }
        }

        /// <summary>
        /// Gets the blackberry group info.
        /// </summary>
        /// <value>The blackberry group info.</value>
        public BlackberryGroupData BlackberryGroupInfo
        {
            get
            {
                return new BlackberryGroupData(txtXmlPath.Text, chkBlackberryGroupRecursive.Checked);
            }
        }
        #endregion Properties

        #region Private Methods
        /// <summary>
        /// Enables disables items on the form according to the situation
        /// </summary>
        private void Enablings()
        {
            gbResxGroup.Enabled = false;
            gbResx.Enabled = false;
            gbResourceGroup.Enabled = false;
            gbResource.Enabled = false;
            gbCsv.Enabled = false;
            gbXml.Enabled = false;
            gbAndroid.Enabled = false;
            gbBlackberry.Enabled = false;

            if (rbResxGroup.Checked)
            {
                gbResxGroup.Enabled = true;
            }

            if (rbResx.Checked)
            {
                gbResx.Enabled = true;
            }

            if (rbResourceGroup.Checked)
            {
                gbResourceGroup.Enabled = true;
            }

            if (rbResource.Checked)
            {
                gbResource.Enabled = true;
            }

            if (rbCsv.Checked)
            {
                gbCsv.Enabled = true;
            }

            if (rbXml.Checked)
            {
                gbXml.Enabled = true;
            }

            if (rbAndroidGroup.Checked)
            {
                gbAndroid.Enabled = true;
            }

            if (rbBlackberryGroup.Checked)
            {
                gbBlackberry.Enabled = true;
            }
        }

        /// <summary>
        /// Loads the form information.
        /// </summary>
        private void LoadForm()
        {
            switch (this.Mode)
            {
                case Enums.LoadModes.Additional:
                    txtResxGroupDir.Text = Settings.Default.FrmLoadAdditional_ResxGroupDir;
                    chkResxGroupRecursive.Checked = Settings.Default.FrmLoadAdditional_ResxGroupIncludeSubdirs;
                    txtResxPath.Text = Settings.Default.FrmLoadAdditional_ResxPath;
                    txtResourceGroupDir.Text = Settings.Default.FrmLoadAdditional_ResourceGroupDir;
                    chkResourceGroupRecursive.Checked = Settings.Default.FrmLoadAdditional_ResourceGroupIncludeSubdirs;
                    txtResourcePath.Text = Settings.Default.FrmLoadAdditional_ResourcePath;
                    txtCsvPath.Text = Settings.Default.FrmLoadAdditional_CsvPath;
                    txtXmlPath.Text = Settings.Default.FrmLoadAdditional_XmlPath;
                    txtAndroidGroupPath.Text = Settings.Default.FrmLoadAdditional_AndroidGroupPath;
                    txtBlackberryGroupPath.Text = Settings.Default.FrmLoadAdditional_BlackberryGroupPath;
                    break;
                case Enums.LoadModes.Patch:
                    txtResxGroupDir.Text = Settings.Default.FrmLoadPatch_ResxGroupDir;
                    chkResxGroupRecursive.Checked = Settings.Default.FrmLoadPatch_ResxGroupIncludeSubdirs;
                    txtResxPath.Text = Settings.Default.FrmLoadPatch_ResxPath;
                    txtResourceGroupDir.Text = Settings.Default.FrmLoadPatch_ResourceGroupDir;
                    chkResourceGroupRecursive.Checked = Settings.Default.FrmLoadPatch_ResourceGroupIncludeSubdirs;
                    txtResourcePath.Text = Settings.Default.FrmLoadPatch_ResourcePath;
                    txtCsvPath.Text = Settings.Default.FrmLoadPatch_CsvPath;
                    txtXmlPath.Text = Settings.Default.FrmLoadPatch_XmlPath;
                    txtAndroidGroupPath.Text = Settings.Default.FrmLoadPatch_AndroidGroupPath;
                    txtBlackberryGroupPath.Text = Settings.Default.FrmLoadPatch_BlackberryGroupPath;
                    break;
                case Enums.LoadModes.Data:
                default:
                    txtResxGroupDir.Text = Settings.Default.FrmLoad_ResxGroupDir;
                    chkResxGroupRecursive.Checked = Settings.Default.FrmLoad_ResxGroupIncludeSubdirs;
                    txtResxPath.Text = Settings.Default.FrmLoad_ResxPath;
                    txtResourceGroupDir.Text = Settings.Default.FrmLoad_ResourceGroupDir;
                    chkResourceGroupRecursive.Checked = Settings.Default.FrmLoad_ResourceGroupIncludeSubdirs;
                    txtResourcePath.Text = Settings.Default.FrmLoad_ResourcePath;
                    txtCsvPath.Text = Settings.Default.FrmLoad_CsvPath;
                    txtXmlPath.Text = Settings.Default.FrmLoad_XmlPath;
                    txtAndroidGroupPath.Text = Settings.Default.FrmLoad_AndroidGroupPath;
                    chkAndroidGroupRecursive.Checked = Settings.Default.FrmLoad_AndroidGroupIncludeSubdirs;
                    txtBlackberryGroupPath.Text = Settings.Default.FrmLoad_BlackberryGroupPath;
                    chkBlackberryGroupRecursive.Checked = Settings.Default.FrmLoad_BlackberryGroupIncludeSubdirs;
                    break;
            }

            #region Get data type
            int datatypeIndex = 0;

            switch (this.Mode)
            {
                case Enums.LoadModes.Additional:
                    datatypeIndex = Settings.Default.FrmLoadAdditional_RbIndex;
                    break;
                case Enums.LoadModes.Patch:
                    datatypeIndex = Settings.Default.FrmLoadPatch_RbIndex;
                    break;
                case Enums.LoadModes.Data:
                default:
                    datatypeIndex = Settings.Default.FrmLoad_RbIndex;
                    break;
            }

            switch (datatypeIndex)
            {
                case 1:
                    rbResx.Checked = true;
                    break;
                case 2:
                    rbResourceGroup.Checked = true;
                    break;
                case 3:
                    rbResource.Checked = true;
                    break;
                case 4:
                    rbCsv.Checked = true;
                    break;
                case 5:
                    rbXml.Checked = true;
                    break;
                case 6:
                    rbAndroidGroup.Checked = true;
                    break;
                case 7:
                    rbBlackberryGroup.Checked = true;
                    break;
                case 0:
                default:
                    rbResxGroup.Checked = true;
                    break;
            }
            #endregion Get data type
        }

        /// <summary>
        /// Saves the form information.
        /// </summary>
        private void SaveForm()
        {
            #region Values
            switch (this.Mode)
            {
                case Enums.LoadModes.Additional:
                    Settings.Default.FrmLoadAdditional_ResxGroupDir = txtResxGroupDir.Text;
                    Settings.Default.FrmLoadAdditional_ResxGroupIncludeSubdirs = chkResxGroupRecursive.Checked;
                    Settings.Default.FrmLoadAdditional_ResxPath = txtResxPath.Text;
                    Settings.Default.FrmLoadAdditional_ResourceGroupDir = txtResourceGroupDir.Text;
                    Settings.Default.FrmLoadAdditional_ResourceGroupIncludeSubdirs = chkResourceGroupRecursive.Checked;
                    Settings.Default.FrmLoadAdditional_ResourcePath = txtResourcePath.Text;
                    Settings.Default.FrmLoadAdditional_CsvPath = txtCsvPath.Text;
                    Settings.Default.FrmLoadAdditional_XmlPath = txtXmlPath.Text;
                    Settings.Default.FrmLoadAdditional_AndroidGroupPath = txtAndroidGroupPath.Text;
                    Settings.Default.FrmLoadAdditional_BlackberryGroupPath = txtBlackberryGroupPath.Text;
                    break;
                case Enums.LoadModes.Patch:
                    Settings.Default.FrmLoadPatch_ResxGroupDir = txtResxGroupDir.Text;
                    Settings.Default.FrmLoadPatch_ResxGroupIncludeSubdirs = chkResxGroupRecursive.Checked;
                    Settings.Default.FrmLoadPatch_ResxPath = txtResxPath.Text;
                    Settings.Default.FrmLoadPatch_ResourceGroupDir = txtResourceGroupDir.Text;
                    Settings.Default.FrmLoadPatch_ResourceGroupIncludeSubdirs = chkResourceGroupRecursive.Checked;
                    Settings.Default.FrmLoadPatch_ResourcePath = txtResourcePath.Text;
                    Settings.Default.FrmLoadPatch_CsvPath = txtCsvPath.Text;
                    Settings.Default.FrmLoadPatch_XmlPath = txtXmlPath.Text;
                    Settings.Default.FrmLoadPatch_AndroidGroupPath = txtAndroidGroupPath.Text;
                    Settings.Default.FrmLoadPatch_BlackberryGroupPath = txtBlackberryGroupPath.Text;
                    break;
                case Enums.LoadModes.Data:
                default:
                    Settings.Default.FrmLoad_ResxGroupDir = txtResxGroupDir.Text;
                    Settings.Default.FrmLoad_ResxGroupIncludeSubdirs = chkResxGroupRecursive.Checked;
                    Settings.Default.FrmLoad_ResxPath = txtResxPath.Text;
                    Settings.Default.FrmLoad_ResourceGroupDir = txtResourceGroupDir.Text;
                    Settings.Default.FrmLoad_ResourceGroupIncludeSubdirs = chkResourceGroupRecursive.Checked;
                    Settings.Default.FrmLoad_ResourcePath = txtResourcePath.Text;
                    Settings.Default.FrmLoad_CsvPath = txtCsvPath.Text;
                    Settings.Default.FrmLoad_XmlPath = txtXmlPath.Text;
                    Settings.Default.FrmLoad_AndroidGroupPath = txtAndroidGroupPath.Text;
                    Settings.Default.FrmLoad_AndroidGroupIncludeSubdirs = chkAndroidGroupRecursive.Checked;
                    Settings.Default.FrmLoad_BlackberryGroupPath = txtBlackberryGroupPath.Text;
                    Settings.Default.FrmLoad_BlackberryGroupIncludeSubdirs = chkBlackberryGroupRecursive.Checked;
                    break;
            }
            #endregion Values

            #region Selected datatype
            int datatypeIndex = 0;

            if (rbResx.Checked)
            {
                datatypeIndex = 1;
            }

            if (rbResourceGroup.Checked)
            {
                datatypeIndex = 2;
            }

            if (rbResource.Checked)
            {
                datatypeIndex = 3;
            }

            if (rbCsv.Checked)
            {
                datatypeIndex = 4;
            }

            if (rbXml.Checked)
            {
                datatypeIndex = 5;
            }

            if (rbAndroidGroup.Checked)
            {
                datatypeIndex = 6;
            }

            if (rbBlackberryGroup.Checked)
            {
                datatypeIndex = 7;
            }

            if (rbResxGroup.Checked)
            {
                datatypeIndex = 0;
            }
            #endregion Selected datatype

            switch (this.Mode)
            {
                case Enums.LoadModes.Additional:
                    Settings.Default.FrmLoadAdditional_RbIndex = datatypeIndex;
                    break;
                case Enums.LoadModes.Patch:
                    Settings.Default.FrmLoadPatch_RbIndex = datatypeIndex;
                    break;
                case Enums.LoadModes.Data:
                default:
                    Settings.Default.FrmLoad_RbIndex = datatypeIndex;
                    break;
            }

            Settings.Default.Save();
        }
        #endregion Private Methods

        #region Events
        /// <summary>
        /// btnLoad Click
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
        private void btnLoad_Click(object sender, EventArgs e)
        {
            bool valid = true;

            errorProviderLoad.SetError(txtResxGroupDir, string.Empty);
            errorProviderLoad.SetError(txtResxPath, string.Empty);
            errorProviderLoad.SetError(txtResourceGroupDir, string.Empty);
            errorProviderLoad.SetError(txtResourcePath, string.Empty);

            errorProviderLoad.SetError(txtCsvPath, string.Empty);
            errorProviderLoad.SetError(txtXmlPath, string.Empty);

            if (rbResxGroup.Checked)
            {
                if (txtResxGroupDir.Text.Length == 0)
                {
                    errorProviderLoad.SetError(txtResxGroupDir, "Path cannot be empty.");
                    valid = false;
                }
                else
                {
                    errorProviderLoad.SetError(txtResxGroupDir, string.Empty);
                }

                this.SelectedFormat = Utils.Enums.Format.ResxGroup;
            }

            if (rbResx.Checked)
            {
                if (txtResxPath.Text.Length == 0)
                {
                    errorProviderLoad.SetError(txtResxPath, "File path cannot be empty.");
                    valid = false;
                }
                else
                {
                    errorProviderLoad.SetError(txtResxPath, string.Empty);
                }

                this.SelectedFormat = Utils.Enums.Format.Resx;
            }

            if (rbResourceGroup.Checked)
            {
                if (txtResourceGroupDir.Text.Length == 0)
                {
                    errorProviderLoad.SetError(txtResourceGroupDir, "Path cannot be empty.");
                    valid = false;
                }
                else
                {
                    errorProviderLoad.SetError(txtResxGroupDir, string.Empty);
                }

                this.SelectedFormat = Utils.Enums.Format.ResourceGroup;
            }

            if (rbResource.Checked)
            {
                if (txtResourcePath.Text.Length == 0)
                {
                    errorProviderLoad.SetError(txtResourcePath, "File path cannot be empty.");
                    valid = false;
                }
                else
                {
                    errorProviderLoad.SetError(txtResourcePath, string.Empty);
                }

                this.SelectedFormat = Utils.Enums.Format.Resource;
            }

            if (rbCsv.Checked)
            {
                if (txtCsvPath.Text.Length == 0)
                {
                    errorProviderLoad.SetError(txtCsvPath, "File path cannot be empty.");
                    valid = false;
                }
                else
                {
                    errorProviderLoad.SetError(txtCsvPath, string.Empty);
                }

                this.SelectedFormat = Utils.Enums.Format.Csv;
            }

            if (rbXml.Checked)
            {
                if (txtXmlPath.Text.Length == 0)
                {
                    errorProviderLoad.SetError(txtXmlPath, "File path cannot be empty.");
                    valid = false;
                }
                else
                {
                    errorProviderLoad.SetError(txtXmlPath, string.Empty);
                }

                this.SelectedFormat = Utils.Enums.Format.Xml;
            }

            if (rbAndroidGroup.Checked)
            {
                if (txtAndroidGroupPath.Text.Length == 0)
                {
                    errorProviderLoad.SetError(txtAndroidGroupPath, "Path cannot be empty.");
                    valid = false;
                }
                else
                {
                    errorProviderLoad.SetError(txtAndroidGroupPath, string.Empty);
                }

                this.SelectedFormat = Utils.Enums.Format.AndroidGroup;
            }

            if (rbBlackberryGroup.Checked)
            {
                if (txtBlackberryGroupPath.Text.Length == 0)
                {
                    errorProviderLoad.SetError(txtBlackberryGroupPath, "Path cannot be empty.");
                    valid = false;
                }
                else
                {
                    errorProviderLoad.SetError(txtBlackberryGroupPath, string.Empty);
                }

                this.SelectedFormat = Utils.Enums.Format.BlackberryGroup;
            }

            if (valid)
            {
                this.DialogResult = DialogResult.OK;
                this.Close();
            }
        }

        /// <summary>
        /// btnLoadResxGroupDir Click
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
        private void btnLoadResxGroupDir_Click(object sender, EventArgs e)
        {
            FolderBrowserDialog fbd = new FolderBrowserDialog();
            fbd.SelectedPath = txtResxGroupDir.Text;
            fbd.ShowDialog();

            this.txtResxGroupDir.Text = fbd.SelectedPath;
        }

        /// <summary>
        /// btnLoadCsvPath Click
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
        private void btnLoadCsvPath_Click(object sender, EventArgs e)
        {
            OpenFileDialog ofd = new OpenFileDialog();
            ofd.Filter = "Comma Separated Values (*.csv)|*.csv|All files (*.*)|*.*";
            ofd.FilterIndex = 0;
            if (txtCsvPath.Text.Length > 0)
            {
                FileInfo fi = new FileInfo(txtCsvPath.Text);
                ofd.InitialDirectory = fi.DirectoryName;
            }
            ofd.RestoreDirectory = true;

            if (ofd.ShowDialog() == DialogResult.OK)
            {
                txtCsvPath.Text = ofd.FileName;
            }
        }

        /// <summary>
        /// FrmLoad FormClosing
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.Windows.Forms.FormClosingEventArgs"/> instance containing the event data.</param>
        private void FrmLoad_FormClosing(object sender, FormClosingEventArgs e)
        {
            if (this.DialogResult == DialogResult.OK)
            {
                this.SaveForm();
            }
        }

        /// <summary>
        /// Handles the Click event of the btnLoadResxPath control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
        private void btnLoadResxPath_Click(object sender, EventArgs e)
        {
            OpenFileDialog ofd = new OpenFileDialog();
            ofd.Filter = "Resource files (*.resx)|*.Resx|All files (*.*)|*.*";
            ofd.FilterIndex = 0;
            if (txtResxPath.Text.Length > 0)
            {
                FileInfo fi = new FileInfo(txtResxPath.Text);
                ofd.InitialDirectory = fi.DirectoryName;
            }
            ofd.RestoreDirectory = true;

            if (ofd.ShowDialog() == DialogResult.OK)
            {
                txtResxPath.Text = ofd.FileName;
            }
        }

        /// <summary>
        /// Handles the TextChanged event of the txtResxPath control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
        private void txtResxPath_TextChanged(object sender, EventArgs e)
        {
            CultureInfo ci = ResxMngr.Instance.GetResxCulture(txtResxPath.Text);
            if (ci == null)
            {
                lblCultureSpecificWarning.Visible = false;
            }
            else
            {
                lblCultureSpecificWarning.Text = string.Concat("File is culture specific (", ci.NativeName, ")!");
                lblCultureSpecificWarning.Visible = true;
            }
        }

        /// <summary>
        /// Handles the Click event of the btnXml control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
        private void btnXml_Click(object sender, EventArgs e)
        {
            OpenFileDialog ofd = new OpenFileDialog();
            ofd.Filter = "Xml files (*.xml)|*.xml|All files (*.*)|*.*";
            ofd.FilterIndex = 0;
            if (txtXmlPath.Text.Length > 0)
            {
                FileInfo fi = new FileInfo(txtXmlPath.Text);
                ofd.InitialDirectory = fi.DirectoryName;
            }
            ofd.RestoreDirectory = true;

            if (ofd.ShowDialog() == DialogResult.OK)
            {
                txtXmlPath.Text = ofd.FileName;
            }
        }

        /// <summary>
        /// Handles the Click event of the btnLoadResourceGroupDir control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
        private void btnLoadResourceGroupDir_Click(object sender, EventArgs e)
        {
            FolderBrowserDialog fbd = new FolderBrowserDialog();
            fbd.SelectedPath = txtResourceGroupDir.Text;
            fbd.ShowDialog();

            this.txtResourceGroupDir.Text = fbd.SelectedPath;
        }

        /// <summary>
        /// Handles the Click event of the btnResource control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
        private void btnResource_Click(object sender, EventArgs e)
        {
            OpenFileDialog ofd = new OpenFileDialog();
            ofd.Filter = "Resource files (*.resources)|*.resources|All files (*.*)|*.*";
            ofd.FilterIndex = 0;

            if (txtResourcePath.Text.Length > 0)
            {
                FileInfo fi = new FileInfo(txtResourcePath.Text);
                ofd.InitialDirectory = fi.DirectoryName;
            }

            ofd.RestoreDirectory = true;

            if (ofd.ShowDialog() == DialogResult.OK)
            {
                txtResourcePath.Text = ofd.FileName;
            }
        }

        /// <summary>
        /// Handles the Click event of the btnLoadAndroidGroupPath control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
        private void btnLoadAndroidGroupPath_Click(object sender, EventArgs e)
        {
            FolderBrowserDialog fbd = new FolderBrowserDialog();
            fbd.SelectedPath = txtAndroidGroupPath.Text;
            fbd.ShowDialog();

            this.txtAndroidGroupPath.Text = fbd.SelectedPath;
        }

        /// <summary>
        /// Handles the Click event of the btnLoadBlackberryGroupPath control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
        private void btnLoadBlackberryGroupPath_Click(object sender, EventArgs e)
        {
            FolderBrowserDialog fbd = new FolderBrowserDialog();
            fbd.SelectedPath = txtBlackberryGroupPath.Text;
            fbd.ShowDialog();

            this.txtBlackberryGroupPath.Text = fbd.SelectedPath;
        }

        /// <summary>
        /// Handles the CheckedChanged event of all the RadioButton controls.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
        private void RadioButton_CheckedChanged(object sender, EventArgs e)
        {
            this.Enablings();
        }
        #endregion Events
    }
}
